<?php

class GuestInfo {

	public function insertRecord($guest){
		
		/**
		
		$guest['web']  访问者访问的页面
		$guest['time']  访问者的时间
		
		**/
		  if(!empty($_SERVER["HTTP_CLIENT_IP"])){
		   $ip = $_SERVER["HTTP_CLIENT_IP"];
		  }
		  if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		   $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
		   if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
		   for ($i = 0; $i < count($ips); $i++) {
			if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
			 $ip = $ips[$i];
			 break;
			}
		   }
		  }


		$ip = $_SERVER["REMOTE_ADDR"];
		
		
		
		try {
			$dir = $_SERVER['DOCUMENT_ROOT'];
			//var_dump($dir);
			include $dir.'/online-system/freenew/config.php';
			$dbh = new PDO($dsn, $user, $pass,$charset); //初始化一个PDO对象
			//echo "连接成功<br/>";
			//你还可以进行一次搜索操作
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$sql = "INSERT INTO `guestinfo` (`id`, `ip`, `web`, `time`) VALUES (NULL, '".$ip."', '".$guest['web']."', '".$guest['time']."')";
			$count = $dbh->exec($sql);
			
			
			$dbh = null;
		} catch (PDOException $e) {
			die ("Error!: " . $e->getMessage() . "<br/>");
		}
		
		return $count;
		
		
		
	

	
	}

}
?>